﻿using System;
using System.Runtime.InteropServices;
using System.Threading.Tasks;
using System.Windows.Forms;
using HtmlAgilityPack;

namespace Tender.HtmlAgilityPack
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }
        public const int KEYEVENTF_KEYUP = 2;

        [DllImport("user32.dll", CharSet = CharSet.Auto, CallingConvention = CallingConvention.StdCall)]
        public static extern void mouse_event(uint dwFlags, int dx, int dy, uint dwData, int dwExtraInfo);

        private const int MOUSEEVENTF_RIGHTDOWN = 0x0002; // 右键按下
        private const int MOUSEEVENTF_RIGHTUP = 0x0004; // 右键抬起

        private async void button1_Click(object sender, EventArgs e)
        {
            // HtmlWeb htmlWeb = new HtmlWeb();
            //var html = htmlWeb.Load("https://docs.qq.com/sheet/DWVh5eU9idXZ1SkZU?tab=s5s8wu&groupUin=");
            // HtmlNode rootnode = html.DocumentNode;
            System.Diagnostics.Process.Start("https://docs.qq.com/sheet/DWVh5eU9idXZ1SkZU?tab=s5s8wu&groupUin=");
            await  Task.Delay(5000);
            int screenWidth = Screen.PrimaryScreen.Bounds.Width;
            int screenHeight = Screen.PrimaryScreen.Bounds.Height;
            int centerX = screenWidth / 2;
            int centerY = screenHeight / 2;
            // 移动鼠标光标到屏幕中央
            Cursor.Position = new System.Drawing.Point(centerX, centerY);
           await Task.Delay(500);
            // 模拟鼠标右键按下
            mouse_event(MOUSEEVENTF_RIGHTDOWN, 0, 0, 0, 0);
            // 模拟鼠标右键抬起
            mouse_event(MOUSEEVENTF_RIGHTUP, 0, 0, 0, 0);
            await Task.Delay(500);
            SendKeys.Send("^a"); // 模拟按下Ctrl+A
            await Task.Delay(500);
            SendKeys.Send("^c"); // 模拟按下Ctrl+A
        }
    }
}
